package com.abocode.aichat.core.application;
import com.abocode.aichat.core.domain.entity.Message;
import com.abocode.aichat.core.domain.repository.RedisMessageRepository;
import com.abocode.aichat.server.context.pipeline.MessagePersistencePipeline;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 *
 * @author guanxf
 * @date 2015/8/6
 */
@Service
public class MessagePersistenceSentService implements MessagePersistencePipeline {
    @Autowired
    private RedisMessageRepository redisMessageRepository;

    @Override
    public void save(Object obj) {
        Message message = JSON.parseObject(obj.toString(),Message.class);
        message.setCreateTime(new Date());
        String  device="all";
        if(StringUtils.isEmpty(message.getDevice())){
            message.setDevice(device);
        }
        redisMessageRepository.save(message);
    }
}
